import jieba
from os import path

d = path.dirname(__file__)

content = open(path.join(d, 'text/chinaHistory.txt'), 'r', encoding='utf-8').read()
words = jieba.lcut(content)
counts = {}
print(words)
for word in words:
    if len(word) == 1:
        continue
    else:
        counts[word] = counts.get(word, 0) + 1

items = list(counts.items())
items.sort(key=lambda x: x[1], reverse=True)
for i in range(20):
    word, count = items[i]
    print(word, count)
